﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using System.Data.SqlClient;
using System.Collections.ObjectModel;
using Helper;

namespace DAL
{
    public class Menu_l3DAL
    {
        //---------------------Menu_l3SearchById-----------------------------
        public List<objMenu_l3> Menu_l3SearchById(int id)
        {

            List<objMenu_l3> lst = new List<objMenu_l3>();

            objMenu_l3 obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));


            SqlDataReader dr = SQLHelper.ExecuteReader("spMenu_l3SearchById", parameterList);
            while (dr.Read())
            {
                obj = new objMenu_l3();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Id_l2 = int.Parse(dr["id_l2"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Position = int.Parse(dr["position"].ToString());

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //---------------------Menu_l3SearchById_l2-----------------------------
        public List<objMenu_l3> Menu_l3SearchById_l2(int id_l2)
        {

            List<objMenu_l3> lst = new List<objMenu_l3>();

            objMenu_l3 obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id_l2", id_l2));


            SqlDataReader dr = SQLHelper.ExecuteReader("spMenu_l3SearchById_l2", parameterList);
            while (dr.Read())
            {
                obj = new objMenu_l3();

                obj.Id = int.Parse(dr["id"].ToString());
                obj.Id_l2 = int.Parse(dr["id_l2"].ToString());
                obj.Name = dr["name"].ToString();
                obj.Position = int.Parse(dr["position"].ToString());

                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //---------------------Menu_l3Insert-----------------------------
        public int Menu_l3Insert(int id_l2, string name, int position)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id_l2", id_l2));
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@position", position));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l3Insert", parameterList);

            return i;
        }

        //---------------------Menu_l3Update-----------------------------
        public int Menu_l3Update(int id, int id_l2, string name, int position)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));
            parameterList.Add(new SqlParameter("@id_l2", id_l2));
            parameterList.Add(new SqlParameter("@name", name));
            parameterList.Add(new SqlParameter("@position", position));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l3Update", parameterList);

            return i;
        }

        //---------------------Menu_l3Delete-----------------------------
        public int Menu_l3Delete(int id)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));

            int i = SQLHelper.ExecuteNonQuery("spMenu_l3Delete", parameterList);

            return i;
        }
    }
}
